package br.com.projetoquestao.repository;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import br.com.projetoquestao.model.Questao;

@Repository
public class QuestaoRepository {
	
	@Autowired
	private SessionFactory sessionFactory;
	
	@Transactional
	public List<Questao> getQuestoes(){
		Criteria criteria  = sessionFactory.getCurrentSession().createCriteria(Questao.class);
		return (List<Questao>) criteria.list();
	}
	
	@Transactional
	public Questao getItem(Long id) {
		return (Questao) sessionFactory.getCurrentSession().get(Questao.class, id);
	}

	@Transactional
	public void salvarPedido(Questao questao) {
		sessionFactory.getCurrentSession().save(questao);
		sessionFactory.getCurrentSession().flush();
	}

}
